import random


class Entity:
    def __init__(self, name, hp, atk):
        self.name = name
        self.hp = hp
        self.atk = atk

    def attack(self, entity):
        print(f"{self.name} 对 {entity.name} 发动了攻击")
        entity.hp = entity.hp - self.atk
        print(f"{entity.name} 受到了 {self.atk}")


class Player(Entity):
    def attack(self, entity):
        skill = random.randint(1, 5)

        if skill < 2:
            print(f"{self.name} 对 {entity.name} 发动了攻击")
            entity.hp = entity.hp - self.atk
            print(f"{entity.name} 受到了 {self.atk}")

        else:
            print(f"{self.name} 对 {entity.name} 触发了暴击！")
            entity.hp = entity.hp - self.atk * 1.5
            print(f"{entity.name} 受到了 {self.atk * 1.5}")


class Monster(Entity):
    def attack(self, entity):
        skill = random.randint(1, 5)

        if skill < 2:
            print(f"{self.name} 对 {entity.name} 发动了攻击")
            entity.hp = entity.hp - self.atk
            print(f"{entity.name} 受到了 {self.atk}")

        else:
            print(f"{self.name} 对 {entity.name} 发动了攻击")
            entity.hp = entity.hp - self.atk
            print(f"{entity.name} 受到了 {self.atk}")
            print(f"{self.name} 触发了吸血！")
            entity.hp = entity.hp * 1.5
            print(f"{self.name} 恢复至 {entity.hp}")


def main():
    player = Player("玩家", random.randint(30, 50), random.randint(5, 10))

    ghost = Monster("幽灵", random.randint(30, 50), random.randint(6, 12))

    fight(player, ghost)


def fight(player, ghost):
    print(
        f"{player.name} hp: {player.hp} atk: {player.atk} 和 {ghost.name} hp: {ghost.hp} atk: {ghost.atk} "
    )

    cont = player.hp > 0 and ghost.hp > 0
    while cont:
        player.attack(ghost)
        if ghost.hp < 0:
            print(f"{ghost.name} 血量归0，结束战斗")
            break

        ghost.attack(player)
        if player.hp < 0:
            print(f"{player.name} 血量归0，结束战斗")
            break


main()
